//
//  TVRechargeViewModel.swift
//  StarTimesON
//
//  Created by Toj on 12/2/22.
//  Copyright © 2022 StarTimes. All rights reserved.
//

import UIKit

class TVRechargeViewModel: NSObject {

    private var sections: [STCommodityTVSectionModel] = []
    var responseSections: ((_ sections: [STCommodityTVSectionModel])->Void)?
    
    private func resetupSections() {
        sections.removeAll()
        
        responseSections?(sections)
    }

    private func loadCardComoditiesSection() -> STCommodityTVSectionModel {
        let section = STCommodityTVSectionModel()
        section.type = .recharge
        
        let commodity = NSObject()
        section.commodities = [commodity]
        
        section.footerSize = CGSize(width: .sr_width, height: 8)
        section.layoutEdgeinset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        let width = CGFloat.sr_width
        let height = width * 252 / 336
        section.cellSize = CGSize(width: width, height: height)
        
        return section
    }
    
    // MARK: - 加购模块
    func setupPurchaseSection() {
        let section = STCommodityTVSectionModel()
        section.type = .purchase
        section.isImage = false
        section.headerSize = .def_cipher
        section.footerSize = CGSize(width: .sr_width, height: 8)
        section.cellSize = CGSize(width: .sr_width, height: 236)
        sections.append(section)
    }
    
    // MARK: - 支付渠道
    private func setupCommodityChannelSection() {
        let section = STCommodityTVSectionModel()
        //section.statisticCategroy = ds_categroy
        section.type = .payChannel
        section.title = "membership_payment".lg_localized
        
        section.cellSize = CGSize(width: .sr_width, height: 47.ui_scale)
        section.headerSize = CGSize(width: .sr_width, height: 32.f_scale + 12)
        section.footerSize = CGSize(width: .sr_width, height: 64.ui_scale)

        let channel = NSObject()
        section.channels = [channel]
        sections.append(section)
    }
    
    // 优惠券模块
    func setupCounponSection() {
        let section = STCommodityTVSectionModel()
        section.type = .coupon
        section.isImage = false
        section.headerSize = .def_cipher
        section.footerSize = CGSize(width: .sr_width, height: 8)
        section.cellSize = CGSize(width: .sr_width, height: 40.ui_scale)
        sections.append(section)
    }
    
    // 用户服务协议
    func setupServiceSection() {
        let section = STCommodityTVSectionModel()
        section.type = .serviceAgreement
        section.isImage = false
        section.headerSize = .def_cipher
        section.footerSize = .def_cipher
        section.cellSize = CGSize(width: .sr_width, height: 52.ui_scale)
        
        sections.append(section)
    }
}

enum STCommodityTVSectionType: Int {
    case card     = 1
    case recharge = 2
    case services = 3
    case purchase = 4
    case payChannel  = 5
    case coupon   = 6
    case serviceAgreement     = 7
}

class STCommoditySectionModel: NSObject {
    /** 数据 */
    // 标题
    public var title = ""
    // 存在图片
    public var isImage = true
    // 当前商品id
    public var productId = 0
    // 标题图片
    public var titleImageUrl = ""
    // 类名, 报数用
    public var statisticCategroy = ""
    
    /** 布局 */
    // section 上下左右的间距
    public var layoutEdgeinset: UIEdgeInsets = .zero
    
    // section 上下左右的间距
    public var cellSize: CGSize = .zero
    
    // 头部大小
    public var headerSize: CGSize = .zero
    
    // 尾部大小
    public var footerSize: CGSize = .zero
    
    // cell之间 垂直间距
    public var minimumLineSpacing: CGFloat = 0.01
    
    // cell之间 水平间距
    public var minimumInteritemSpacing: CGFloat = 0.01
}


class STCommodityTVSectionModel: STCommoditySectionModel {
    
    var type: STCommodityTVSectionType = .card
    
    var cardCellModel: NSObject?
    
    var commodities: [NSObject] = []
    // 商品规格支付渠道
    var channels: [NSObject] = []
    
    var services: [NSObject] = []
}
